import React from 'react';
import { Form, Table } from 'antd';

const TYPE_MAP = {
    1: {
        point: '迟到',
        info: '最大次数不超过'
    },
    2: {
        point: '早退',
        info: '最大次数不超过'
    },
    3: {
        point: '缺卡',
        info: '最大次数不超过'
    },
    4: {
        point: '请假',
        info: '最多小时不超过'
    },
    5: {
        point: '旷工',
        info: '最大次数不超过'
    }
};

const renderStr = (text, record) => (
    <>
        {text}
        {record.type === 4 ? '小时' : '次'}
    </>
);

const AttendanceDetail = ({ data, ...rest }) => {
    const { attendanceAssessVO } = data || {};
    const { detail = [] } = attendanceAssessVO || {};

    const columns = [
        {
            title: '类型',
            dataIndex: 'point'
        },
        {
            title: '条件',
            dataIndex: 'info'
        },
        {
            title: '周评考核标准',
            dataIndex: 'weekValue',
            render: renderStr
        },
        {
            title: '月评考核标准',
            dataIndex: 'monthValue',
            render: renderStr
        },
        {
            title: '季评考核标准',
            dataIndex: 'quarterValue',
            render: renderStr
        }
    ];

    const getFinalList = () =>
        detail.map(item => ({
            ...item,
            ...TYPE_MAP[item.type]
        }));

    return (
        <Form {...rest}>
            <Form.Item label="考勤要求">
                考评周期间考勤明细存在
                {typeof attendanceAssessVO?.requirementsCount !== 'undefined'
                    ? attendanceAssessVO?.requirementsCount
                    : '--'}
                项不符合时，则为不合格
            </Form.Item>
            <Form.Item label="考勤明细">
                <Table
                    rowKey="type"
                    columns={columns}
                    dataSource={getFinalList()}
                    pagination={false}
                    scroll={{ x: 'max-content' }}
                />
            </Form.Item>
            <Form.Item label="考勤指标说明">{attendanceAssessVO?.instructions || '--'}</Form.Item>
        </Form>
    );
};

export default AttendanceDetail;
